﻿using Demo.Domains.Entities.Sys;
using Demo.PetaPoco.Application.Dtos.Menu;
using Microsoft.Extensions.DependencyInjection;
using PmSoft.Core;

namespace Demo.PetaPoco.Application.Services.Menu;

[Inject(ServiceLifetime.Scoped)]
public class MenuService(MenuRepository menuRepository)
{
	/// <summary>
	/// 获取路由记录列表。
	/// </summary>
	/// <returns></returns>
	public async Task<List<RouteRecord>> GetRouteRecordsAsync()
	{
		var menus = await menuRepository.GetAllMenuAsync();
		menus = menus.Where(m => m.Type == MenuType.Menu);
		return MenuConverter.ToRouteRecordDtos(menus);
	}

	/// <summary>
	/// 获取权限编码列表。
	/// </summary>
	/// <returns></returns>
	public async Task<IEnumerable<string>> GetPermCodesAsync()
	{
		var menus = await menuRepository.GetAllMenuAsync();
		menus = menus.Where(m => m.Type == MenuType.Menu);
		return menus.Select(m => m.PermCode);
	}
}
